package com.udp2;
import java.io.*;
import java.net.*;


/**
 * Created by sh04799 on 2017/10/23.
 */

public class UDPServerThread extends Thread {
	public static void main(String[] args) {
		UDPServerThread thread=new UDPServerThread(8080);
		thread.start();
	}
    private int mPort;
    private static String TAG = "UDPServerThread";

    public UDPServerThread(int port) {
        this.mPort = port;

    }

    @Override
    public void run() {

        DatagramSocket server = null;
        try {
        
            server = new DatagramSocket(mPort);
        	while(true){
            byte[] recvBuf = new byte[1024];
            DatagramPacket recvPacket = new DatagramPacket(recvBuf, recvBuf.length);
            server.receive(recvPacket);
            String recvStr = new String(recvPacket.getData(), 0,
                    recvPacket.getLength());
            System.out.println("rec=="+recvStr);
        	}
        } catch (SocketException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}
